package cn.ld.module.system.dal.mapper.logger;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.api.logger.dto.OperateLogPageInDTO;
import cn.ld.module.system.controller.admin.logger.vo.operatelog.OperateLogPageInVO;
import cn.ld.module.system.dal.entity.logger.OperateLogEntity;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface OperateLogMapper extends BaseMapperX<OperateLogEntity> {

    default PageResult<OperateLogEntity> selectPage(OperateLogPageInVO pageInDTO) {
        return selectPage(pageInDTO, new LambdaQueryWrapperX<OperateLogEntity>()
                .eqIfPresent(OperateLogEntity::getUserId, pageInDTO.getUserId())
                .eqIfPresent(OperateLogEntity::getBizId, pageInDTO.getBizId())
                .likeIfPresent(OperateLogEntity::getType, pageInDTO.getType())
                .likeIfPresent(OperateLogEntity::getSubType, pageInDTO.getSubType())
                .likeIfPresent(OperateLogEntity::getAction, pageInDTO.getAction())
                .betweenIfPresent(OperateLogEntity::getCreateTime, pageInDTO.getCreateTime())
                .orderByDesc(OperateLogEntity::getId));
    }

    default PageResult<OperateLogEntity> selectPage(OperateLogPageInDTO pageInDTO) {
        return selectPage(pageInDTO, new LambdaQueryWrapperX<OperateLogEntity>()
                .eqIfPresent(OperateLogEntity::getType, pageInDTO.getType())
                .eqIfPresent(OperateLogEntity::getBizId, pageInDTO.getBizId())
                .eqIfPresent(OperateLogEntity::getUserId, pageInDTO.getUserId())
                .orderByDesc(OperateLogEntity::getId));
    }

}
